<?php

/* @var $this \yii\web\View */
/* @var $content string */

use common\models\Post;
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use frontend\assets\AppAsset;
use common\widgets\Alert;
use yii\helpers\Url;

AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
  <meta charset="UTF-8">
    <title><?= Html::encode($this->params['page']['page_title']) ?></title>
    <?= $this->registerMetaTag(['name' => 'keywords', 'content' => $this->params['page']['page_keywords']]) ?>
    <?= $this->registerMetaTag(['name' => 'description', 'content' => $this->params['page']['page_description']]) ?>
  <link rel="stylesheet" href="http://static.tianpinwang.com.cn/v1/css/global.css"/>
  <link rel="stylesheet" href="http://static.tianpinwang.com.cn/v1/css/main.css"/>
  <link rel="stylesheet" href="http://static.tianpinwang.com.cn/v1/icons/font-awesome.min.css">
  <link rel="stylesheet" href="http://static.tianpinwang.com.cn/v1/icons/iconfont/iconfont.css">

  <script src="http://static.tianpinwang.com.cn/v1/js/jquery-1.11.2.min.js"></script>
  <script src="http://static.tianpinwang.com.cn/v1/js/global.js"></script>
  <script src="http://static.tianpinwang.com.cn/v1/js/layer/layer.js"></script>
  <?= Html::csrfMetaTags() ?>
  <?php $this->head() ?>
<?= $this->params['w_config']['statistics_code'] //统计代码?>    
</head>
<body>
<?php $this->beginBody() ?>
  <div class="header">
    <div class="content-wrap positionr">
      <a href="/" class="logo left">
        <img src="http://static.tianpinwang.com.cn/v1/images/logo.png" alt=""/>
      </a>
      <!-- <ul class="icons left">
        <li>
          <p>厂家直供<br>正品保障</p>
          <img src="http://static.tianpinwang.com.cn/v1/images/head-icon1.png" alt=""/>
        </li>
        <li>
          <p>免费拿样<br>批发无忧</p>
          <img src="http://static.tianpinwang.com.cn/v1/images/head-icon2.png" alt=""/>
        </li>
        <li>
          <p>全国送达<br>48小时发货</p>
          <img src="http://static.tianpinwang.com.cn/v1/images/head-icon3.png" alt=""/>
        </li>
      </ul> -->
      <div class="left slogen"><img src="http://static.tianpinwang.com.cn/v1/images/index/slogen.png" alt=""></div>

      <img src="" alt="">
      <div class="left positionr">
        <form >
          <input type="text" class="serachTxt" placeholder="<?=Html::encode(Yii::$app->request->get('name')?Yii::$app->request->get('name'):'碳酸氢铵')?>">
          <input type="button" class="searchBtn" value="搜索">
          <input type="button" class="searchBtn" value="搜索">
        </form>
        <p class="hotTags">
          <a href="<?= Url::toRoute(['product/17']);?>">一水柠檬酸</a>
          <a href="<?= Url::toRoute(['product/33']);?>">木糖醇</a>
          <a href="<?= Url::toRoute(['product/43']);?>">山梨酸钾</a>
          <a href="<?= Url::toRoute(['product/36']);?>">三聚磷酸钠</a>
        </p>
        <div class="shopping">
          <?php
          //获取购物车数据
          $user_id = Yii::$app->user->id;
          $carts = \common\models\ShoppingCart::find()->where('user_id=:user_id', [':user_id'=>$user_id])->orderBy('id DESC')->all();
          $count_carts = count($carts);
          $total_num = 0;//初始化商品总件数
          $total_price = 0;//初始化商品总价格
          ?>
          <i class="iconfont icon-gouwuche"></i>
          <?php if($user_id && $count_carts):?>
            <i class="messageInfo" id="total_cart"><?=$count_carts?></i>
          <?php endif;?>

          <div class="popList">
            <?php if($user_id && $count_carts ):?>
              <ul class="cartList">
                <?php foreach( $carts as $v ):?>
                  <?php
                    $total_num += $v->product_num;
                    $total_price = bcadd($total_price, ($v->product_price*$v->product_num), 2);
                  ?>
                  <li>
                    <a href="<?= Url::toRoute(['product/'.$v->product_id]);?>">
                      <img src="<?=$v->img_url?$v->img_url:'http://static.tianpinwang.com.cn/v1/images/goods001.png'?>" class="img">
                      <p class="name"><?=$v->title?></p>
                      <span class="info">￥<span><?=floatval($v->product_price)?></span>×<span><?=$v->product_num?></span>个</span>
                      <span class="close inlineBlock" onclick="cart_del(<?=$v->id?>)"><img src="http://static.tianpinwang.com.cn/v1/images/closeIcon.png"></span>
                    </a>
                  </li>
                <?php endforeach;?>
              </ul>
              <div class="btn">
                <p class="totalNumber">共<span class="number" id="total_num"><?=$total_num?></span>件商品</p>
                <p class="totalPrice">￥<span id="total_price"><?=floatval($total_price)?></span> 元</p>
                <a href="/mycount/cart-list" class="inlineBlock">查看进货单</a>
              </div>
            <?php else:?>
              <p class="nullInfo">购物车空空哦，赶紧选购吧<img src="http://static.tianpinwang.com.cn/v1/images/qqIcon.png" alt=""></p>
            <?php endif;?>
          </div>
        </div>

      <?php if(Yii::$app->user->isGuest){?>
        <div class="sign">
          <a href="/site/login">登录</a>
          <a href="/site/register">免费注册</a>
        </div>
      </div>
      <?php }else{?>
        </div>
        <div class="logged">
          <div class="avatar left">
            <img src="http://static.tianpinwang.com.cn/file/2016/07/21/8v1yj43vr5p3avdn.jpg" alt="">
            <span style = 'display: none;'></span>
          </div>
          <div class="name left"><?=Yii::$app->user->identity->username?></div>
          <img src="http://static.tianpinwang.com.cn/v1/images/downIcon.png" alt="" class="downIcon">
          <div class="popNav">
            <ul>
              <a href = '/mycount/center'><li>我的账户<span style = 'display: none;'></span></li></a> 
              <a href = '/order'><li>已买到的货品</li></a>
              <a href = '/account'><li>账号设置</li></a>
              <a href="javascript:void(0);" id = 'logout'><li>安全退出</li></a>
            </ul>
          </div>
        </div>
      <?php }?>

    </div>
  </div>
  <div class="nav">
    <div class="content-wrap">
      <a href="" class="main-nav"><img src="http://static.tianpinwang.com.cn/v1/images/menu-icon.png" alt="">全部商品目录</a>
      <div id="lv1_nav">
        <a href="/">首页</a>
        <a href="<?= Url::toRoute(['product/index/', 'lv1' => 72])?>">食品添加剂</a>
        <a href="<?= Url::toRoute(['product/index/', 'lv1' => 95])?>">食品配料</a>
        <a href="<?= Url::toRoute(['product/index/', 'lv1' => 96])?>">食品调味料</a>
      </div>
      <div class="right positionr" id="rightnav">
        <img src="http://static.tianpinwang.com.cn/v1/images/line-icon.png" alt="" class="line">
        <a href="/help/6">关于添品网</a>
        <a href="/help/2">帮助中心</a>
        <a href="javascript:;" class="phone"><img src="http://static.tianpinwang.com.cn/v1/images/phone-icon.png" alt=""><?= $this->params['w_config']['contact_tel'] ?> </a>
      </div>
    </div>
  </div>

 
    <div class="countCenter">

    <div class="mcCont">
    <div class="content-wrap">
      <div class="countNavs left">
        <a href="/mycount/center" class="tt0 current"><i class="iconfont icon-user"></i>我的账户<i class="iconfont icon-right"></i></a>
        <ul class="navList">
          <li>
            <dl>
              <dt><i class="icon-down iconfont"></i>我的交易</dt>
              <dd><a class="y" href="/order" class="current">已买到的货品<i class="iconfont icon-right"></i></a></dd>
              <dd><a class="a" href="/mycount/cart-list">进货单<i class="iconfont icon-right"></i></a></dd>
              <dd><a href="/account/collect">我收藏的货品<i class="iconfont icon-right"></i></a></dd>
             <!--  <dd><a href="">退换货管理<i class="iconfont icon-right"></i></a></dd> -->
              <!-- <dd><a href="/mycount/message">消息中心<i class="iconfont icon-right"></i></a></dd> -->
            </dl>
          </li>
          <li>
            <dl>
              <dt><i class="icon-down iconfont"></i>我的资金</dt>
              <dd><a href="/mycount/money">资金明细<i class="iconfont icon-right"></i></a></dd><!-- 
              <dd><a href="/withdraw/charge">充值<i class="iconfont icon-right"></i></a></dd>
              <dd><a href="/withdraw/index">提现<i class="iconfont icon-right"></i></a></dd> -->
            </dl>
          </li>
          <li>
            <dl>
              <dt><i class="icon-down iconfont"></i>账户资料</dt>
              <!-- <dd><a href="/members/cer">企业会员认证<i class="iconfont icon-right"></i></a></dd> -->
              <dd><a href="/account">基本信息<i class="iconfont icon-right"></i></a></dd>
              <dd><a href="/account/shipaddress">收货地址<i class="iconfont icon-right"></i></a></dd>
              <dd><a href="/account/resetpassword">修改密码<i class="iconfont icon-right"></i></a></dd>
            </dl>
          </li>
        </ul>
      </div>
     
    <?= $content ?>
    

   <div class="footer">
    <div class="content-wrap" style="height:210px;">
    <?php
      $cache = Yii::$app->cache;
     
      // 尝试从缓存中取回 $data 
      $footer_list = $cache->get('footer_list');

      if ($footer_list === false) {

          $footer_list[0] = Post::itemAlias('post_category_id');

          foreach ($footer_list[0] as $k => $v) {
              $footer_list[1][$k] = Post::find()->select('id,title')
                                  ->where("status = 1 AND post_category_id =".$k)
                                  ->asArray()->all();
          }
          $cache->set('footer_list', $footer_list);
      }
    ?>
      <?php foreach ($footer_list[0] as $k => $v): ?>
        
        <?php if ($k<6): ?>
            <dl>
              <dt><?=Html::encode($v)?></dt>
              <?php foreach ($footer_list[1][$k] as $key => $value): ?>
                <dd>
                <a href="/help/<?=Html::encode($value['id'])?>">
                  <?=Html::encode($value['title'])?>
                </a>
                </dd>
              <?php endforeach ?>
              
            </dl>
        <?php endif ?>

      <?php endforeach ?>

      <!-- <dl>
        <dt>进货指南</dt>
        <dd><a href="/help/4">免费拿样</a></dd>
        <dd><a href="/help/5">进货流程</a></dd>
        <dd><a href="/help/6">订单查询</a></dd>
      </dl>
      <dl>
        <dt>支付/配送</dt>
        <dd><a href="/help/3">在线支付</a></dd>
        <dd><a href="/help/4">物流运输</a></dd>
        <dd><a href="/help/5">签货验收</a></dd>
      </dl>
      <dl>
        <dt>售后服务</dt>
        <dd><a href="/help/10">退换货政策</a></dd>
        <dd><a href="/help/11">退换货办理</a></dd>
        <dd><a href="/help/12">退货说明</a></dd>
      </dl>
      <dl>
        <dt>关于我们</dt>
        <dd><a href="/help/6">关于添品</a></dd>
        <dd><a href="/help/7">联系我们</a></dd>
      </dl> -->
      <dl  class="kf">
        <dt>客服热线</dt>
        <dd class="phonenumber"><?= $this->params['w_config']['contact_tel'] ?></dd>
        <!-- <dd class="icons">
          <a href="" target="_blank">
            <img src="http://static.tianpinwang.com.cn/v1/images/qqIcon.png" alt="">
          </a>
          <a href="" target="_blank">
            <img src="http://static.tianpinwang.com.cn/v1/images/weiboIcon.png" alt="">
          </a>
        </dd> -->
      </dl>
      <div class="erweima">
        <h1 class="tt">添品网官方微信</h1>
        <p class="txt">扫一扫，关注最新优惠</p>
        <img src="<?= $this->params['w_config']['weixin_fuwuhao'] ?>" alt="" class="img">
      </div>
    </div>
    <p class="copyRight">Copyright ©2016 <?= $this->params['w_config']['domain_base'] ?> All Rights Reserved <?=$this->params['w_config']['icp']?></p>
  <div style="width:300px;margin:0 auto; padding:20px 0; margin-bottom:-25px">
    <a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=33010802006122" style="display:inline-block;text-decoration:none;height:20px;line-height:20px;"><img src="http://static.tianpinwang.com.cn/file/2016/08/04/zculgj3h6e1liwxv.png" style="float:left;"/><p style="float:left;height:20px;line-height:20px;margin: 0px 0px 0px 5px; color:#939393;">浙公网安备 33010802006122号</p></a>
  </div>

</div>
  
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>

<style type="text/css">#layui-layer1{width:260px}.popNav a{color: #3d3d3d}</style>  
<script type="text/javascript">
  $(function(){
    $('.searchBtn').click(function(){
      var name;
      if($('.serachTxt').val()){
        name = $('.serachTxt').val();
      }else{
        name = $('.serachTxt').attr('placeholder')
      }
      window.location.href = "/product/index/?name="+name;
    });
  })

  $(function(){
    $('#logout').click(function(){
      layer.confirm('您确认要退出登录吗？', {
          btn: ['确认','取消'], //按钮
          shade: false, //不显示遮罩
          icon:3,   //5
      }, function(){
          location.href="/site/logout";
      });
    });
    
    $('.logged').on('mouseenter',function(){
      $('.popNav').css('display','block');
    }).on('mouseleave',function(){
      $('.popNav').css('display','none');
    });
  });

  function cart_del(_id){
    $.ajax({
      type: "POST",
      url: "/shopping-cart/delete",
      data: "id="+_id+"&_csrf=<?=Yii::$app->request->getCsrfToken()?>",
      dataType: "json",
      success: function(data){

          if(!data.errNo){
              $(this).parent().parent().remove();

              if( data.total_num ){
                  $('#total_num').html(data.total_num);
                  $('#total_price').html(data.total_price);
                  $('#total_cart').html(data.count_carts);
              }else{
                  $('.popList .btn').remove();
                  $('.popList .cartList').remove();
                  $('#total_cart').remove();
                  $('.popList').html('<p class="nullInfo">购物车空空哦，赶紧选购吧<img src="http://static.tianpinwang.com.cn/v1/images/qqIcon.png"></p>');
              }
          }else{
              alert(data.msg);
          }
      }
    });
  }

  //取消搜索框聚焦回车键提交表单
  document.getElementsByTagName('form')[0].onkeydown = function(e){
    var e = e || event;
    var keyNum = e.which || e.keyCode;
    return keyNum==13 ? false : true;
  };

</script>